package com.itheima.api.list.demo01;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo01 {

    public static void main(String[] args) {

        Student s1 = new Student("刘德华", 18);
        Student s2 = new Student("古天乐", 19);
        Student s3 = new Student("张家辉", 20);

        List<Student> list = new ArrayList<Student>();

        list.add(s1);
        list.add(s2);
        list.add(s3);

        //普通for循环
        for (int i = 0; i < list.size(); i++) {

            Student s = list.get(i);
            System.out.println(s.getName() + "----" + s.getAge());

        }

        System.out.println("------------------------------------------------");

        //增强for循环
        for(Student s : list){
            System.out.println(s.getName() + "----" + s.getAge());
        }

        System.out.println("------------------------------------------------");

        //迭代器
        Iterator<Student> iterator = list.iterator();

        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next.getName() + "----" + next.getAge());
        }

        System.out.println("------------------------------------------------");

        //forEach
        list.forEach(s -> System.out.println(s.getName() + "----" + s.getAge()));

    }

}
